<div class="Item hr">
    <span class="fr"><a href="{:U('Roles/index')}" class="btn">角色管理</a></span>
    <span class="fr"><a href="{:U('SysAdminUser/add')}" class="btn">添加用户</a></span>
    <div class="current">用户列表</div>
</div>
<form>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab">
        <thead>
            <tr>
                <td>用户名</td>
                <td>角色</td>
                <td>备注</td>
                <td>状态</td>
                <td>创建时间</td>
                <td>最后登录时间</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <volist name="SysUserList" id="admin" empty="$empty">
            <tr align="center">
                <td>{$admin['username']}</td>
                <td>{$admin['roles']['name']}</td>
                <td>{$admin['remark']}</td>
                <td>
                <if condition="$admin['status'] == 1">
                <a href="javascript:;" class="icon icon-color icon-check setStatus" data-url='{:U("toggleStatus")}' data-id="{$admin.id}" data-name="{$admin['name']}" data-status='no' title="点击禁用"></a>
                <else/>
                <a href="javascript:;" class="icon icon-color icon-close setStatus" data-url='{:U("toggleStatus")}' data-id="{$admin.id}" data-name="{$admin['name']}" data-status='yes' title="点击启用"></a>
                </if>
                </td>
                <td>{:date('Y-m-d H:i:s', $admin['subtime'])}</td>
                <td>{:date('Y-m-d H:i:s', $admin['logintime'])}</td>
                <td><a href="{:U('SysAdminUser/edit', array('id' => $admin['id']))}" class="icon icon-black icon-edit" title="编辑"></a> <if condition="$admin['id'] gt 1">  <a href="javascript:;" class="deleted icon icon-black icon-trash" value="{:U('SysAdminUser/delete', array('id' => $admin['id']))}" name="{$admin['username']}" title="删除"></a> </if></td>
            </tr>
            </volist>
        </tbody>
    </table>
</form>

<div class="page">
    {$page}
</div>
<script type="text/javascript">
$(function(){
    $(".deleted").click(function(){
        var url = $(this).attr("value");
        var name = $(this).attr("name");

        popup.confirm("您确定删除 <b>" + name + "</b> 管理员？", '温馨提示',function(action){
            if(action == 'ok'){
                $.getJSON(url, function(json){
                    if (json.status) {
                        popup.success(json.info);
                        setTimeout(function(){
                            popup.close("asyncbox_success");
                        },2000);
						 setTimeout(function(){
							top.window.location.reload();
						},3000);
                   } else {
                        popup.error(json.info);
                        setTimeout(function(){
                            popup.close("asyncbox_error");
                        },2000);
                    }

                });
            }
        });

        return false;
    });
	
    $(".setStatus").click(function(){
        var url = $(this).data("url");
        var name = $(this).data("name");
        var id = $(this).data("id");
        var status = $(this).data("status");

        popup.confirm("您确定修改？", '温馨提示',function(action){
            if(action == 'ok'){
                $.ajax({
					'url' : url,
					'dataType' : 'JSON',
					'type' : 'POST',
					'data' : {'id' : id, 'status' : status},
					'success' : function(json){
						if (json.status) {
							popup.success(json.info, '设置成功', function(){
								if(json.url){
									window.location.href = json.url;
								}else{
									top.window.location.reload();
								}
							});
							setTimeout(function(){
								popup.close("asyncbox_success");
							},2000);
		
							setTimeout(function(){
								top.window.location.reload();
							},3000);
						} else {
							popup.error(json.info);
							setTimeout(function(){
								popup.close("asyncbox_error");
							},2000);
						}
					}
				});
            }
        });

        return false;
    });
});
</script>
